﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using InnovaApp.Layers.SecurityLayer.Models.AccountModels.MembershipServices;
using System.Web.Routing;

namespace InnovaApp.Layers.SecurityLayer.Controllers
{
	public class LogOffController : Controller
	{
		public IFormsAuthenticationService FormsService { get; set; }
		public IMembershipService MembershipService { get; set; }

		/// <summary>
		/// Initializes data that might not be available when the constructor is called.
		/// </summary>
		/// <param name="requestContext">The HTTP context and route data.</param>
		protected override void Initialize(RequestContext requestContext)
		{
			if (FormsService == null) { FormsService = new FormsAuthenticationService(); }
			if (MembershipService == null) { MembershipService = new AccountMembershipService(); }

			base.Initialize(requestContext);
		}

		#region LogOff
		/// <summary>
		/// URL: /LogOff
		/// </summary>
		/// <returns></returns>
		[Authorize]
		public ActionResult Index()
		{
			FormsService.SignOut();
			Session.Abandon();
			return RedirectPermanent("~/");
		}

		#endregion
	}
}
